package com.cs2340.practice;

import java.util.ArrayList;

import android.util.Log;


/**
 * This class validates user input
 * @author Jasmine
 *
 */
public class Validator {
	
	private String TAG = "Validation";
	public Validator(){
		
	}
	

	/**
	 *  Checks if the two entered passwords are the same
	 * @param password
	 * @param retypePassword second password typed
	 * @return true if the passwords match, false otherwise
	 */
	public boolean passwordMatch(String password, String retypePassword){
		boolean truth = false;
		if(password.equals(retypePassword)){
			truth = true;
		}else{
			truth = false;
		}
		return truth;
	}
	

	/**
	 * @param usernames list of existing usernames
	 * @param username username new desired username
	 * @return true if username exists, false otherwise
	 */
	public boolean usernameExists(ArrayList<String>  usernames, String username ){

		//ArrayList<String> usernames = myUserDatabaseAdapter.getUsernames();
		
		Log.i(TAG, "Validating: " + username + " against " +usernames );
		
		boolean truth = false;
		if (usernames.contains(username)) { // username check
			truth = true;
		} else {
			truth = false;
		}
		
		return truth;
		
	}


	/**
	 * @param enteredPassword password the user entered 
	 * @param username user who entered the password
	 * @param databasePassword password the of the user from database
	 * @return checks if password matches record password
	 */
	public boolean checkPassword(String enteredPassword, String databasePassword) {
		boolean truth = false;
		
		if (enteredPassword.equals(databasePassword))
			truth = true;
		else
			truth = false;
	
		return truth;
	}

}